require 'yaml'
class ServerData
  attr_accessor :host,:port,:sname,:cname,:module,:pass,:cfg,:prefix,:projects
  def initialize(cfg="data/default_server.scfg",prefix="",sname=nil,host=nil,port=nil,pass=nil,name=nil,_module=nil,projects={})
    go = 1
    if cfg != nil
      go = go * 2
      @server = YAML.load_file(cfg)
    end
    if go == 2
        go = 1
	if host==nil
	  go = go * 0
	end
	if port == nil
	  go = go * 0
	end
	if name==nil
	  go = go * 0
	end
	if pass == nil
	  go = go * 0
	end
	if cfg == nil
	  go = go * 0
	end
        if go == 1
          @cname,@sname,@host,@port,@pass,@module,@cfg,@projects,@prefix=cname,sname,host,port,pass,_module,cfg,projects,prefix
          @server = self
        end
    end
  end
  def get_server
   return @server
  end
  def write
    File.open("data/#{@sname}_server.scfg","w") {|f|
      f.puts "#{self.to_yaml}"
    }
  end
end